package reflect;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ResourceBundle;

/**
 * 对类方法进行反编译
 * 但是只能反编译出方法title 具体内容
 * 跟反编译属性有点蕾丝
 */
public class ReflectTest09 {
    public static void main(String[] args) throws ClassNotFoundException {
        ResourceBundle bundle =ResourceBundle.getBundle("classinfo2");
        Class c = Class.forName(bundle.getString("className1"));

        StringBuilder s = new StringBuilder();
        Method[] methods = c.getDeclaredMethods();
        s.append(Modifier.toString(c.getModifiers())+"class" +c.getSimpleName()+"{\n");
        //public boolean Login(String name,String pwd){
        for (Method method:methods) {
            s.append("\t");
            s.append(Modifier.toString(method.getModifiers()));
            s.append(" ");
            s.append(method.getReturnType().getSimpleName());
            s.append(" ");
            s.append(method.getName());
            s.append("(");
             //参数
            Class[] para = method.getParameterTypes();
            for (Class p:para) {
                s.append(p.getSimpleName() + ",");
            }
            //最后一个多了一个逗号 所以需要截取字符串
           // s.substring(0,s.length());
            s.deleteCharAt(s.length()-1);
            s.append("){}\n");

        }

        s.append("}");
        System.out.println(s);
        }

    }

